package com.bank.doman.auth.controller;


import cn.dev33.satoken.stp.StpUtil;
import com.bank.common.io.RestVo;
import com.bank.doman.auth.io.vo.UserVo;
import com.bank.doman.auth.server.UserServiceI;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 菜单接口
 */
@Api(tags = "用户登录接口")
@RequestMapping("/user")
@RestController
public class UserController {

    @Resource
    private UserServiceI userServiceI;

    @PostMapping("/login")
    @ApiOperation("用户登录接口")
    public RestVo create(@RequestParam String account,@RequestParam String password) {
        UserVo userVo = userServiceI.login(account,password);
        StpUtil.login(userVo.getId());
        return RestVo.ok(StpUtil.getTokenInfo());
    }


    @ApiOperation("获取登录用户数据")
    @GetMapping("/userInfo")
    public RestVo userinf() {
        System.out.println(StpUtil.getLoginId());
        return RestVo.ok(userServiceI.userInfo(StpUtil.getLoginIdAsLong()));
    }

    @ApiOperation("用户登出接口")
    @PostMapping("logout")
    public RestVo logout() {
        StpUtil.logout();
        return RestVo.ok();
    }


}
